package com.yc.cloud.common.pay.config;

import com.wechat.pay.java.core.RSAAutoCertificateConfig;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
@Slf4j
@ConditionalOnProperty(prefix = "wx.pay", name = "enabled", havingValue = "true")
public class WxPayAutoCertificateConfig {

    @Resource
    private WxPayConfig wxPayConfig;

    /**
     * 初始化商户配置
     */
    @Bean
    public RSAAutoCertificateConfig rsaAutoCertificateConfig() {
        log.info("WxPayAutoCertificateConfig....");
        return new RSAAutoCertificateConfig.Builder().merchantId(wxPayConfig.getMerchantId()).privateKeyFromPath(wxPayConfig.getPrivateKey()).merchantSerialNumber(wxPayConfig.getMerchantSerialNumber()).apiV3Key(wxPayConfig.getApiV3Key()).build();
    }
//    @Bean
//    public JsapiServiceExtension jsapiServiceExtension() {
//        val rsaAutoCertificateConfig = new RSAAutoCertificateConfig.Builder().merchantId(wxPayConfig.getMerchantId()).privateKeyFromPath(wxPayConfig.getPrivateKey()).merchantSerialNumber(wxPayConfig.getMerchantSerialNumber()).apiV3Key(wxPayConfig.getApiV3Key()).build();
//        //请求微信支付相关配置
//        return new JsapiServiceExtension.Builder().config(rsaAutoCertificateConfig).signType("RSA") // 不填默认为RSA
//                .build();
//    }


}
